﻿/*******************************************************************************
*  Project      : Minigate Golfin                                 
*  Program ID   : join_02.js                                 
*  Description  : 회원가입 
*
********************************************************************************
*  Program History                                                            
*  Date        Author    Description                                          
*  ----------  --------  -------------------------------------------------------- 
*  2012-04-16  김효순    Created.
*  2012-04-18  김효순    Complete.
*******************************************************************************/

jQuery(function($){
	if(_util.getCookie("join_check") != "Y"){
		alert("약관동의 후 이용가능한 페이지 입니다. 약관동의 페이지로 이동합니다.");
		document.location.href = "join_01.html";
		return;
	}
	
	_util.delCookie("join_check", "/");
	
	
	// 이름
	function clsName()
	{
		this._HTMLDom = null;
		this._ERRMSG = {
			"_NOVALUE": "실명인증을 해 주십시요."
		}
		this.errMsg = null;
		
		this._init();
	}
	
	clsName.prototype = {
		_init: function(){
			var $layer = $("div#container dl.mem_join tbody tr:eq(0)");
			this._HTMLDom = {
				"$layer": $layer
			}
			
			$layer.find("input:text").prop("readonly", true);
		}
		, $getLayer: function(){
			return this._HTMLDom["$layer"];
		}
		, getValue: function(){
			return this._HTMLDom["$layer"].find("input:text").val();
		}
		, setValue: function(val){
			this.$getLayer().find("input:text").val(val);
		}
		, isValid: function(){
			var val = this._HTMLDom["$layer"].find("input:text").val();
			
			this.errMsg = null;
			if(!val.trim()){
				this.errMsg = "_NOVALUE";
				return false;
			}
			
			return true;
		}
		, getError: function(){
			if(!this.errMsg) return null;
			else return this._ERRMSG[this.errMsg];
		}
		, focus: function(){
			this._HTMLDom["$layer"].find("input:text").trigger("focus");
		}
	}
	
	// 성별
	function clsGender()
	{
		this._HTMLDom = null;
		this._ERRMSG = {
			"_INVALID": "성별을 체크해 주십시요."
		}
		this._listData = null;
		this.errMsg = null;
		
		this._init();
	}
	
	clsGender.prototype = {
		_init: function(){
			var $layer = $("div#container dl.mem_join tbody tr:eq(1)");
			this._HTMLDom = {
				"$layer": $layer
			}
			
			$layer.find("input:radio").attr("name", "rdoGender");
			
			this._listData = ["M", "F"]
		}
		, getValue: function(){
			var $layer = this._HTMLDom["$layer"];
			var idx = $layer.find("input:radio").index($layer.find("input:radio:checked"));
			
			return this._listData[idx];
		}
		, getError: function(){
			if(!this.errMsg) return null;
			else return this._ERRMSG[this.errMsg];
		}
		, isValid: function(){
			var $layer = this._HTMLDom["$layer"];
			
			this.errMsg = null;
			if($layer.find("input:radio:checked").length == 0){
				this.errMsg = "_INVALID";
				return false;
			}
			
			return true;
		}
		, focus: function(){
			this._HTMLDom["$layer"].find("input:radio").trigger("focus");
		}
	}
	
	// 아이디
	function clsId()
	{
		this._HTMLDom = null;
		this._ERRMSG = {
			"_NOVALUE": "아이디를 입력해주세요."
			, "_NOCHECK": "아이디 중복확인을 해주세요."
			, "_INVALID": "아이디는 4~12이하 영문 또는 숫자만 가능합니다."
		}
		this.errMsg = null;
		this.checkId = null;
		
		this._init();
	}
	
	clsId.prototype = {
		_init: function(){
			var $layer = $("div#container dl.mem_join tbody tr:eq(2)");
			this._HTMLDom = {
				"$layer": $layer
			}
			
			$layer.find("input:text").attr("maxLength", 12);
		}
		, $getBtnUniq: function(){
			return this._HTMLDom["$layer"].find("img[alt='중복확인']");
		}
		, getValue: function(){
			return this._HTMLDom["$layer"].find("input:text").val();
		}
		, setValue: function(val){
			return this._HTMLDom["$layer"].find("input:text").val(val);
		}
		, setCheck: function(val){
			this.checkId = val
		}
		, getError: function(){
			if(!this.errMsg) return null;
			else return this._ERRMSG[this.errMsg];
		}
		, isValid: function(){
			var $layer = this._HTMLDom["$layer"];
			var val = $layer.find("input:text").val();
			var reg = /^[a-zA-Z0-9]{4,12}$/i;
			
			this.errMsg = null;
			if(val.length == 0){
				this.errMsg = "_NOVALUE";
				return false;
			}else if(!reg.test(val)){
				this.errMsg = "_INVALID";
				return false;
			}else if(this.checkId != this.getValue()){
				this.errMsg = "_NOCHECK";
				return false;
			}
			
			return true;
		}
		, focus: function(){
			this._HTMLDom["$layer"].find("input:text").trigger("focus");
		}
	}
	
	// 닉네임
	function clsNick()
	{
		this._HTMLDom = null;
		this._ERRMSG = {
			"_NOVALUE": "닉네임을 입력해주세요."
			, "_NOCHECK": "닉네임 중복확인을 해주세요."
			, "_INVALID": "닉네임은 2~6 이하만 가능합니다."
		}
		this.errMsg = null;
		this.checkNick = null;
		
		this._init();
	}
	
	clsNick.prototype = {
		_init: function(){
			var $layer = $("div#container dl.mem_join tbody tr:eq(3)");
			this._HTMLDom = {
				"$layer": $layer
			}
			
			$layer.find("input:text").attr("maxLength", 6);
		}
		, $getBtnUniq: function(){
			return this._HTMLDom["$layer"].find("img[alt='중복확인']");
		}
		, getValue: function(){
			return this._HTMLDom["$layer"].find("input:text").val();
		}
		, setValue: function(val){
			var $layer = this._HTMLDom["$layer"];
			
			$layer.find(":text").val(val);
		}
		, setCheck: function(val){
			this.checkNick = val;
		}
		, getError: function(){
			if(!this.errMsg) return null;
			else return this._ERRMSG[this.errMsg];
		}
		, isValid: function(){
			var $layer = this._HTMLDom["$layer"];
			var val = $layer.find("input:text").val();
			
			this.errMsg = null;
			if(val.length == 0){
				this.errMsg = "_NOVALUE";
				return false;
			}else if(val.length < 2 || val.length > 6){
				this.errMsg = "_INVALID";
				return false;
			}else if(this.checkNick != this.getValue()){
				this.errMsg = "_NOCHECK";
				return false;
			}
			
			return true;
		}
		, focus: function(){
			this._HTMLDom["$layer"].find("input:text").trigger("focus");
		}
	}
	
	// 비밀번호
	function clsPasswd()
	{
		this._HTMLDom = null;
		this._ERRMSG = {
			"_NOVALUE": "비밀번호를 입력해주세요."
			, "_DIFFER": "비밀번호와 비밀번호 확인이 일치하지 않습니다."
			, "_INVALID": "비밀번호는 4~12이하 영문 또는 숫자만 가능합니다."
		}
		this.errMsg = null;
		this.$errObj = null;
		
		this._init();
	}
	
	clsPasswd.prototype = {
		_init: function(){
			var $layer = $("div#container dl.mem_join tbody").find("tr:eq(4), tr:eq(5)");
			this._HTMLDom = {
				"$layer": $layer
			}
			
			$layer.find("input:password").each(function(){
				$(this).attr("maxLength", 12);
			});
		}
		, getError: function(){
			if(!this.errMsg) return null;
			else return this._ERRMSG[this.errMsg];
		}
		, isValid: function(){
			var $layer = this._HTMLDom["$layer"];
			var val = $layer.find("input:password").eq(0).val();
			var val_confirm = $layer.find("input:password").eq(1).val();
			var reg = /^[a-zA-Z0-9]{4,12}$/i;
			
			this.errMsg = null;
			this.$errObj = null;
			if(val.length == 0){
				this.errMsg = "_NOVALUE";
				this.$errObj = $layer.find("input:password").eq(0);
				return false;
			}else if(!reg.test(val)){
				this.errMsg = "_INVALID";
				this.$errObj = $layer.find("input:password").eq(0);
				return false;
			}else if(this.getValue() != val_confirm){
				this.errMsg = "_DIFFER";
				this.$errObj = $layer.find("input:password").eq(1);
				return false;
			}
			
			return true;
		}
		, getValue: function(){
			var $layer = this._HTMLDom["$layer"];
			
			return $layer.find(":password").eq(0).val();
		}
		, focus: function(){
			var $layer = this._HTMLDom["$layer"];
			
			if(this.$errObj) this.$errObj.trigger("focus");
			else $layer.find("input:password").eq(0).trigger("focus");
		}
	}
	
	// 이메일
	function clsEmail()
	{
		this._HTMLDom = null;
		this._ERRMSG = {
			"_NOVALUE": "이메일을 입력해주세요."
			, "_INVALID": "정상적인 이메일주소가 아닙니다."
			, "_NOCHECK": "이메일 중복체크를 해 주세요."
		}
		this.errMsg = null;
		this.$errObj = null;
		this.checkEmail = null;
		
		this._init();
	}
	
	clsEmail.prototype = {
		_init: function(){
			var $layer = $("div#container dl.mem_join tbody tr:eq(6)");
			this._HTMLDom = {
				"$layer": $layer
			}
			
			var e = _gf.getEmailList();
			$layer.find("select").empty();
			$layer.find("select").append("<option value=''>직접입력</option>");
			for(var i=0;i<e.length;i++){
				$layer.find("select").append("<option value='" + e[i]["이메일"]+ "'>" + e[i]["텍스트"] + "</option>");
			}
			
			$layer.find("input:checkbox").prop("checked", true);
		}
		, $getLayer: function(){
			return this._HTMLDom["$layer"];
		}
		, getError: function(){
			if(!this.errMsg) return null;
			else return this._ERRMSG[this.errMsg];
		}
		, isValid: function(){
			var $layer = this._HTMLDom["$layer"];
			var val1 = $layer.find("input:text:eq(0)").val();
			var val2 = $layer.find("input:text:eq(1)").val();
			var reg1 = /^[\w\-\.]+$/i;
			var reg2 = /^(?:(?:[\w\-]+\.)+[a-zA-Z]{2,})$/i;
			
			this.errMsg = null;
			this.$errObj = null;
			
			if(val1.length == 0 || val2.length == 0){
				this.errMsg = "_NOVALUE";
				
				if(val1.length == 0) this.$errObj = $layer.find("input:text:eq(0)");
				else if(val2.length == 0) this.$errObj = $layer.find("input:text:eq(1)");
				return false;
			}else if(!(reg1.test(val1) && reg2.test(val2))){
				this.errMsg = "_INVALID"
				
				if(!reg1.test(val1)) this.$errObj = $layer.find("input:text:eq(0)");
				else if(!reg2.test(val2)) this.$errObj = $layer.find("input:text:eq(1)");
				return false;
			}else if(this.checkEmail != this.getValue()){
				this.errMsg = "_NOCHECK";
				return false;
			}
			
			return true;
		}
		, $getSelect: function(){
			var $layer = this._HTMLDom["$layer"];
			
			return $layer.find("select");
		}
		, setValue: function(){
			var $layer = this._HTMLDom["$layer"];
			var val = $layer.find("option:selected").val();
			
			$layer.find("input:text:eq(1)").val(val);
		}
		, setValues: function(val){
			var $layer = this.$getLayer();
			
			var arrE = val.split("@");
			$layer.find("input:text:eq(0)").val(arrE[0]);
			$layer.find("input:text:eq(1)").val(arrE[1]);
		}
		// 이벤트 및 정보메일 수신
		, getYNReceive: function(){
			var $layer = this._HTMLDom["$layer"];
			
			if($layer.find("input:checkbox").is(":checked")) return "Y";
			else return "N";
		}
		, getValue: function(){
			var $layer = this._HTMLDom["$layer"];
			var val1 = $layer.find(":text:eq(0)").val();
			var val2 = $layer.find(":text:eq(1)").val();
			
			return val1 + "@" + val2;
		}
		, focus: function(){
			if(this.$errObj) this.$errObj.trigger("focus");
			else this.$getLayer().find("input:text:eq(0)").trigger("focus");
		}
		, setCheck: function(val){
			this.checkEmail = val;
		}
	}
	
	// 핸드폰
	function clsHp()
	{
		this._HTMLDom = null;
		this._ERRMSG = {
			"_NOVALUE": "휴대폰 번호를 입력해 주십시요."
			, "NOTELECOM": "통신사를 선택해 주십시요."
			, "_INVALID": "정상적인 휴대폰 번호가 아닙니다."
			, "NOCHECK": "휴대폰 인증체크를 해 주세요."
		}
		this._listData = [
			"통신사선택", "KT", "SKT", "LGT"
		];
		this.errMsg = null;
		this.$errObj = null;
		this.checkHp = null;
		
		this._init();
	}
	
	clsHp.prototype = {
		_init: function(){
			var $layer = $("div#container dl.mem_join tbody tr:eq(7)");
			this._HTMLDom = {
				"$layer": $layer
			}
			
			$layer.find("select").empty();
			for(var i=0;i<this._listData.length;i++){
				$layer.find("select").append("<option value='" + this._listData[i] + "'>" + this._listData[i].replace("LGT", "LG유플러스") + "</option>");
			}
			
			$layer.find("input:text:eq(0)").attr("maxLength", 3);
			$layer.find("input:text:gt(0)").attr("maxLength", 4);
		}
		, $getLayer: function(){
			return this._HTMLDom["$layer"];
		}
		, getError: function(){
			if(this.errMsg) return this._ERRMSG[this.errMsg];
			else return null;
		}
		, isValid: function(bAuth){
			var $layer = this._HTMLDom["$layer"];
			var val1 = $layer.find("input:text:eq(0)").val();
			var val2 = $layer.find("input:text:eq(1)").val();
			var val3 = $layer.find("input:text:eq(2)").val();
			var reg1 = /^[0-9]{3}$/i;
			var reg2 = /^[0-9]{3,4}$/i;
			var reg3 = /^[0-9]{3,4}$/i;
			
			this.errMsg = null;
			this.$errObj = null;
			
			if($layer.find("select option:eq(0)").is(":selected")){
				this.errMsg = "NOTELECOM";
				this.$errObj = $layer.find("select");
				return false;
			}else if(val1.length == 0 || val2.length == 0 || val3.length == 0){
				this.errMsg = "_NOVALUE";
				
				if(val1.length == 0) this.$errObj = $layer.find("input:text:eq(0)");
				else if(val2.length == 0)  this.$errObj = $layer.find("input:text:eq(1)");
				else if(val3.length == 0)  this.$errObj = $layer.find("input:text:eq(2)");
				return false;
			}else if(!reg1.test(val1)){
				this.errMsg = "_INVALID";
				this.$errObj = $layer.find("input:text:eq(0)");
				return false;
			}else if(!reg2.test(val2)){
				this.errMsg = "_INVALID";
				this.$errObj = $layer.find("input:text:eq(1)");
				return false;
			}else if(!reg3.test(val3)){
				this.errMsg = "_INVALID";
				this.$errObj = $layer.find("input:text:eq(2)");
				return false;
			}else if(!bAuth && this.checkHp != (this.getTeleValue() + this.getValue())){
				this.errMsg = "NOCHECK";
				return false;
			}
			
			return true;
		}
		, getTeleValue: function(){
			var $layer = this._HTMLDom["$layer"];
			
			var n = $layer.find("select option").index($layer.find("select option:selected"));
			return this._listData[n];
		}
		, setTeleValue: function(val){
			var $layer = this.$getLayer();
			
			var n = $.inArray(val, this._listData);
			
			if(n > -1) $layer.find("select option").eq(n).prop("selected", true);
		}
		, getValue: function(){
			var $layer = this._HTMLDom["$layer"];
			
			return $layer.find("input:text:eq(0)").val() + "-" + $layer.find("input:text:eq(1)").val() + "-" + $layer.find("input:text:eq(2)").val()
		}
		, setValue: function(val){
			var $layer = this.$getLayer();
			
			var ar = val.split("-");
			$layer.find("input:text:eq(0)").val(_util.nvl(ar[0]));
			$layer.find("input:text:eq(1)").val(_util.nvl(ar[1]));
			$layer.find("input:text:eq(2)").val(_util.nvl(ar[2]));
		}
		, focus: function(){
			if(this.$errObj) this.$errObj.trigger("focus");
			else this._HTMLDom["$layer"].find("select").trigger("focus");
		}
		, setCheck: function(val){
			this.checkHp = val;
		}
	}
	
	// 조인룸초대 수신여부
	function clsJoinroomYN()
	{
		this._HTMLDom = null;
		
		this._init();
	}
	
	clsJoinroomYN.prototype = {
		_init: function(){
			var $layer = $("div#container tr:eq(8)");
			this._HTMLDom = {
				"$layer": $layer
			}
			
			$layer.find("input:radio").attr("name", "rdoJoinroomYN");
			
			this.setValue("Y");
		}
		, getValue: function(){
			var $layer = this._HTMLDom["$layer"];
			var n = $layer.find("input:radio").index($layer.find("input:radio:checked"));
			
			var szRet = "";
			switch(n){
				case 0:
					szRet = "Y";
					break;
				case 1:
					szRet = "N";
					break;
			}
			
			return szRet;
		}
		, setValue: function(val){
			var $layer = this._HTMLDom["$layer"];
			
			switch(val){
				case "Y":
					n = 0;
					break;
				case "N":
					n = 1;
					break;
			}
			
			$layer.find("input:radio").eq(n).prop("checked", true);
		}
	}
	
	// 프로필사진
	function clsProfileImage()
	{
		this._HTMLDom = null;
		this.infoData = null;
		
		this._init();
	}
	
	clsProfileImage.prototype = {
		_init: function(){
			var $layer = $("div#container dl.mem_join tbody tr:eq(11)");
			this._HTMLDom = {
				"$layer": $layer
			}
			this.setData({});
		}
		, $getLayer: function(){
			return this._HTMLDom["$layer"];
		}
		, setData: function(thisData){
			this.infoData = thisData;
			this.display();
		}
		, display: function(){
			var $layer = this._HTMLDom["$layer"];
			
			var $tmp = $layer.find("span.btn_del").children().clone(true);
			$layer.find("span.btn_del").html(_util.nvl(this.infoData["원본파일명"])).append($tmp);
			
//			$layer.find("span.btn_del").show().contents().filter(function(){
//				return this.nodeType==3
//			}).after(_util.nvl(this.infoData["원본파일명"])).remove();
		}
		, getFile: function(){
			if(this.infoData) return this.infoData["파일명"];
			else return "";
		}
		, getOrigFile: function(){
			if(this.infoData) return this.infoData["원본파일명"];
			else return "";
		}
		, getThumb: function(){
			if(this.infoData) return this.infoData["섬네일"];
			else return "";
		}
		, setAttach: function(callback){
			var $layer = this.$getLayer();
			var $img = $layer.find("img[alt='사진첨부']");
			var p = $img.position();
			
			_gf.setUploadFileImage($img, null, function(ret){
				callback.apply(null, arguments);
			}, p);
		}
	}
	
	// 연령대
	function clsAge()
	{
		this._HTMLDom = null;
		this.listData = null;
		
		this._init();
	}
	
	clsAge.prototype = {
		_init: function(){
			var $layer = $("div#container dl.mem_join tbody tr:eq(12)");
			this._HTMLDom = {
				"$layer": $layer
			}
		}
		, setList: function(thisData){
			this.listData = [{
				"나이코드": ""
				, "내용": "-- 연령대선택 --"
			}].concat(thisData);
			
			this.display();
		}
		, display: function(){
			var $layer = this._HTMLDom["$layer"];
			var thisClass = this;
			
			$layer.find("select").empty();
			for(var i=0;i<this.listData.length;i++){
				$layer.find("select").append("<option />");
			}
			$layer.find("option").each(function(n){
				$(this).text(thisClass.listData[n]["내용"]);
			});
		}
		, getKey: function(n){
			return this.listData[n]["나이코드"];
		}
		, getValue: function(){
			var $layer = this._HTMLDom["$layer"];
			var n = $layer.find("option").index($layer.find("option:selected"));
			
			return this.getKey(n);
		}
		, isLoaded: function(){
			if(this.listData) return true;
			else return false;
		}
	}
		
	
	// 지역
	function clsArea()
	{
		this._HTMLDom = null;
		this.listData = null;
		
		this._init();
	}
	
	clsArea.prototype = {
		_init: function(){
			var $layer = $("div#container dl.mem_join tbody tr:eq(13)");
			this._HTMLDom = {
				"$layer": $layer
			}
		}
		, setList: function(thisData){
			this.listData = [{
				"지역코드": ""
				, "내용": "-- 지역선택 --"
			}].concat(thisData);
			
			this.display();
		}
		, display: clsAge.prototype.display
		, getKey: function(n){
			return this.listData[n]["지역코드"];
		}
		, getValue: clsAge.prototype.getValue
		, isLoaded: clsAge.prototype.isLoaded
	}
	
	
	// 직업
	function clsJob()
	{
		this._HTMLDom = null;
		
		this._init();
	}
	
	clsJob.prototype = {
		_init: function(){
			var $layer = $("div#container dl.mem_join tbody tr:eq(14)");
			this._HTMLDom = {
				"$layer": $layer
			}
			
			$layer.find("input:text").attr("placeholder", "직업을 입력해 주세요.");
			$layer.find("input:text").val("");
		}
		, getValue: function(){
			return this._HTMLDom["$layer"].find("input:text").val();
		}
	}
	
	
	// 핸디
	function clsHandi()
	{
		this._HTMLDom = null;
		
		this._init();
	}
	
	clsHandi.prototype = {
		_init: function(){
			var $layer = $("div#container dl.mem_join tbody tr:eq(15)");
			this._HTMLDom = {
				"$layer": $layer
			}
			
			$layer.find("input:text").attr("placeholder", "입력");
			$layer.find("input:text").val("");
		}
		, $getLayer: function(){
			return this._HTMLDom["$layer"];
		}
		, getValue: clsJob.prototype.getValue
	}
	
	
	
	// 평균타수
	function clsAvg()
	{
		this._HTMLDom = null;
		
		this._init();
	}
	
	clsAvg.prototype = {
		_init: function(){
			var $layer = $("div#container dl.mem_join tbody tr:eq(16)");
			this._HTMLDom = {
				"$layer": $layer
			}
			
			$layer.find("input:text").attr("placeholder", "평균타수를 입력해 주세요.");
			$layer.find("input:text").val("");
		}
		, $getLayer: function(){
			return this._HTMLDom["$layer"];
		}
		, getValue: clsJob.prototype.getValue
		, setValue: function(val){
			this.$getLayer().find("input:text").val(val);
		}
	}
	
	
	
	
	
	function clsComm()
	{
		this._init();
	}
	
	clsComm.prototype = {
		_init: function(){
			
		}
		, joinSubmit: function(arg){
			var thisClass = this;
			
			var serviceName = "insert";
			
			document.objGlobal.ajax({
				"sid":"US001",
				"servicename":serviceName,
				"listcount":10,
				"currpageno":1
			}, {
				"userName": arg["이름"]
				, "sex": arg["성별"]
				, "userId": arg["아이디"]
				, "nickname": arg["닉네임"]
				, "pw": arg["비밀번호"]
				, "email": arg["이메일"]
				, "emailreceiveYn": arg["정보수신여부"]
				, "telInc": arg["통신사"]
				, "phonenum": arg["휴대폰"]
				, "inviteReceiveYn": arg["조인룸초대수신여부"]
				, "saveFileName": arg["프로필사진"]
				, "orgnFileName": arg["프로필원본사진"]
				, "thumb": arg["프로필섬네일"]
				, "age": arg["연령대"]
				, "region": arg["지역"]
				, "job": arg["직업"]
				, "handy": arg["핸디"]
				, "average": arg["평균타수"]
				, "userType": 1
				, "authYn": "N"
				, "userLevel": "A"
			}, function(ret){
				var res = {
					"결과코드":ret["msp"]["contents"]["serviceResult"]
					, "아이디": arg["아이디"]
					, "메시지": document.objGlobal.getResultMsg(ret)
				}
				
				document.objControl.finishJoinSubmit(res);
			});
		}
		// 이메일 중복체크
		, emailCheck: function(arg){
			var thisClass = this;
			
			//ajax
			var serviceName = "checkEmailDuplication";
			var options = {
				"email": arg["이메일"]
			}
			_gf.ajax({
				"sid": "US001"
				, "servicename": serviceName
			}, options, function(ret){
				var res = {
					"결과코드": ret["msp"]["contents"]["serviceResult"]
					, "메시지": _gf.getResultMsg(ret)
					, "이메일": arg["이메일"]
				}
				
				document.objControl.finishEmailCheck(res);
			});
		}
		// 실명인증
		, getAuthName: function(arg){
			arg = arg || {};
			arg["콜백"] = arg["콜백"] || function(){};
			
			//ajax
			var serviceName = "getEncData";
			var options = {
				"returnUrl": "http://" + document.domain + "/name_auth"
			}
			_gf.ajax({
				"sid": "US001"
				, "servicename": serviceName
			}, options, function(ret){
				var res = {
					"결과코드": ret["msp"]["contents"]["serviceResult"]
					, "메시지": _gf.getResultMsg(ret)
					, "결과값": {}
				}
				
				var items = ret["msp"]["contents"]["items"];
				if(items){
					var obj = items;
					res["결과값"] = {
						"메시지": _util.nvl(obj["message"])
						, "암호화코드": _util.nvl(obj["encData"])
					}
				}
				
				arg["콜백"].apply(null, [res]);
			});
		}
	}
	
	
	function clsControl()
	{
		this.objComm = null;
		this.objName = null;
		this.objGender = null;
		this.objId = null;
		this.objNick = null;
		this.objPasswd = null;
		this.objEmail = null;
		this.objHp = null;
		this.objJoinroomYN = null;
		this.objProfileImage = null;
		this.objAge = null;
		this.objArea = null;
		this.objJob = null;
		this.objHandi = null;
		this.objAvg = null;
		
		this._init();
	}
	
	clsControl.prototype = {
		_init: function(){
			this.objComm = new clsComm();
			this.objName = new clsName();
			this.objGender = new clsGender();
			this.objId = new clsId();
			this.objNick = new clsNick();
			this.objPasswd = new clsPasswd();
			this.objEmail = new clsEmail();
			this.objHp = new clsHp();
			this.objJoinroomYN = new clsJoinroomYN();
			this.objProfileImage = new clsProfileImage();
			this.objAge = new clsAge();
			this.objArea = new clsArea();
			this.objJob = new clsJob();
			this.objHandi = new clsHandi();
			this.objAvg = new clsAvg();
			
			this._preload();
			this._bind();
		}
		, _preload: function(){
			var thisClass = this;
			
			_gf.spinStart();
			_gf.getAgeCodeList({
				"콜백": function(ret, listData){
					thisClass.objAge.setList(listData);
				}
			});
			
			_gf.getAreaCodeList({
				"콜백": function(ret, listData){
					thisClass.objArea.setList(listData);
				}
			});
			
			_util.executeThread(function(){
				return (thisClass.objAge.isLoaded() && thisClass.objArea.isLoaded());
			}, function(){
				_gf.spinEnd();
				thisClass._start();
			});
		}
		, _start: function(){
			
		}
		, _bind: function(){
			var thisClass = this;
			
			$("div#top_menu a").attr("id", "idPermissionLink");
			
			// 실명 인증
			this.objName.$getLayer().on("click", "input:text, img[alt='실명인증']", function(){
				thisClass.authName();
			});
			
			// 아이디 중복확인
			this.objId.$getBtnUniq().click(function(){
				var winIdCheck = window.open("../popup/id_check.html?q_type=id", "winIdCheck", "width=500, height=500, scrollbars=no");
				if(winIdCheck) winIdCheck.focus();
			});
			
			// 닉네임 중복확인
			this.objNick.$getBtnUniq().click(function(){
				var winNickCheck = window.open("../popup/id_check.html?q_type=nick", "winNickCheck", "width=500, height=500, scrollbars=no");
				if(winNickCheck) winNickCheck.focus();
			});
			
			// 이메일 선택박스
			this.objEmail.$getSelect().change(function(){
				thisClass.objEmail.setValue();
			});
			
			this.objProfileImage.setAttach(function(ret){
				thisClass.uploadFile(ret);
			});
			
			// 핸드폰인증
			this.objHp.$getLayer().on("click", "img[alt='인증번호 받기']", function(){
				thisClass.goHPAuthPage();
			});
			
			// 사진
			this.objProfileImage.$getLayer().on("click", "img['삭제']", function(){
				var alt = $(this).attr("alt");
				switch(alt){
					case "삭제":
						thisClass.objProfileImage.setData({});
						break;
				}
			});
			
			// 이메일 중복체크
			this.objEmail.$getLayer().on("click", "img[alt='중복확인']", function(){
				thisClass.objComm.emailCheck({
					"이메일": thisClass.objEmail.getValue()
				});
			});
			
			
			// 가입하기
			$("div#container p.mem_btn>a:eq(0)").click(function(){
				// validate
				if(!thisClass.objName.isValid()){
					alert(thisClass.objName.getError());
					thisClass.objName.focus();
					return;
				}else if(!thisClass.objGender.isValid()){
					alert(thisClass.objGender.getError());
					thisClass.objGender.focus();
					return;
				}else if(!thisClass.objId.isValid()){
					alert(thisClass.objId.getError());
					thisClass.objId.focus();
					return;
				}else if(!thisClass.objNick.isValid()){
					alert(thisClass.objNick.getError());
					thisClass.objNick.focus();
					return;
				}else if(!thisClass.objPasswd.isValid()){
					alert(thisClass.objPasswd.getError());
					thisClass.objPasswd.focus();
					return;
				}else if(!thisClass.objEmail.isValid()){
					alert(thisClass.objEmail.getError());
					thisClass.objEmail.focus();
					return;
				}else if(!thisClass.objHp.isValid()){
					alert(thisClass.objHp.getError());
					thisClass.objHp.focus();
					return;
				}
				
				document.objGlobal.spinStart("sending...");

				thisClass.objComm.joinSubmit({
					"이름": thisClass.objName.getValue()
					, "성별": thisClass.objGender.getValue()
					, "아이디": thisClass.objId.getValue()
					, "닉네임": thisClass.objNick.getValue()
					, "비밀번호": thisClass.objPasswd.getValue()
					, "이메일": thisClass.objEmail.getValue()
					, "정보수신여부": thisClass.objEmail.getYNReceive()
					, "통신사": thisClass.objHp.getTeleValue()
					, "휴대폰": thisClass.objHp.getValue()
					, "조인룸초대수신여부": thisClass.objJoinroomYN.getValue()
					, "프로필사진": thisClass.objProfileImage.getFile()
					, "프로필원본사진": thisClass.objProfileImage.getOrigFile()
					, "프로필섬네일": thisClass.objProfileImage.getThumb()
					, "연령대": thisClass.objAge.getValue()
					, "지역": thisClass.objArea.getValue()
					, "직업": thisClass.objJob.getValue()
					, "핸디": thisClass.objHandi.getValue()
					, "평균타수": thisClass.objAvg.getValue()
				});
			});
			
			// 취소하기
			$("div#container p.mem_btn>a:eq(1)").click(function(){
				history.back();
			});
			
			// 평균타수 자동계산
			this.objHandi.$getLayer().on("change", "input:text", function(){
				var v = thisClass.objHandi.getValue();
				v = parseInt(v);
				
				if(!v && v != 0){
					thisClass.objAvg.setValue("");
				}else{
					thisClass.objAvg.setValue(v+72);
				}
			});
		}
		// 가입하기 완료
		, finishJoinSubmit: function(ret){
			_gf.spinEnd();
			if(ret["메시지"]) alert(ret["메시지"]);
			if(ret["결과코드"] != "00000") return;
			
			document.objGlobal.loginProc({
				"아이디": ret["아이디"]
			});
			
			document.location.href = "join_03.html";
		}
		// 이메일 중복체크 완료
		, finishEmailCheck: function(ret){
			if(ret["메시지"]) alert(ret["메시지"]);
			if(ret["결과코드"] != "00000") return;
			
			this.objEmail.setCheck(ret["이메일"]);
		}
		// 실명인증 완료
		, finishAuthName: function(ret){
			if(ret["메시지"]) alert(ret["메시지"]);
			if(ret["결과코드"] != "00000") return;
			
			$("body").append('<form><input type="hidden" name="enc_data" value="' + ret["결과값"]["암호화코드"]+ '"></form>');
			var $f = $("form:last");
			var winNameAuth = window.open('', 'winNameAuth', 'width=450, height=350,toolbar=no,directories=no,scrollbars=no,resizable=no,status=no,menubar=no,top=0,left=0');
			$f.attr({
				"action": "https://cert.namecheck.co.kr/NiceID/certnc_input.asp"
				, "target": "winNameAuth"
				, "id": "idPermissionForm"
				, "method": "post"
			});
			$f.trigger("submit");
			
		}
		// 중복체크로부터 사용하기
		, returnCheck: function(w, q_type, val){
			if(w) w.close();
			
			var obj = null;
			
			switch(q_type){
				case "id":
					obj = this.objId;
					break;
				case "nick":
					obj = this.objNick;
					break;
			}
			
			obj.setValue(val);
			obj.setCheck(val);
		}
		// 휴대폰 중복체크 완료
		, returnHPCheck: function(w, tele, val){
			if(w) w.close();
			
			var objTele = {
				2 : "KT"
				, 1: "SKT"
				, 3: "LGT"
			}
			
			alert("휴대폰 인증이 완료되었습니다.");
			
			this.objHp.setCheck(objTele[tele] + val);
		}
		// 실명인증 완료
		, returnNameAuth: function(w, nm){
			if(w) w.close();
			this.objName.setValue(nm);
		}
		// 중복체크 오픈시 초기값 전송
		, getValue: function(q_type){
			switch(q_type){
				case "id":
					return this.objId.getValue()
					break;
				case "nick":
					return this.objNick.getValue();
					break;
			}
		}
		// sky72아이디로 회원가입하기
		, setSky72: function(w, ret){
			var thisClass = this;
			// ajax
			
			if(w) w.close();
			
			this.objName.setValue(ret["이름"]);
			this.objId.setValue(ret["아이디"]);
			this.objId.setCheck(ret["아이디"]);
			this.objNick.setValue(ret["이름"]);
			this.objEmail.setValues(ret["이메일"]);
			this.objHp.setTeleValue(ret["통신사"]);
			this.objHp.setValue(ret["휴대폰"]);
			
			
//			setTimeout(function(){
//				document.objGlobal.spinEnd();
//				alert("회원 연동을 성공적으로 완료하였습니다. SKY72회원정보로 동일하게 이용이 가능합니다.");
//				document.location.href = "join_03.html";
//			}, 2000);
		}
		, uploadFile: function(ret){
			if(ret["결과코드"] != "00000"){
				alert("파일업로드 오류입니다.");
				return;
			}
			
			var fs = ret["파일리스트"][0]["파일크기"]-0;
		
			if(fs >= 3 * 1024 * 1024){
				alert("사진용량은 3MB까지만 등록 가능합니다. 파일 용량을 확인하여 주세요.");
				return;
			}
			
			this.objProfileImage.setData(ret["파일리스트"][0]);
		}
		// 실명인증
		, authName: function(){
			var thisClass = this;
			
			this.objComm.getAuthName({
				"콜백": function(ret){
					thisClass.finishAuthName(ret);
				}
			});
		}
		// 인증번호 받기 이동
		, goHPAuthPage: function(){
			if(!this.objHp.isValid(true)){
				alert(this.objHp.getError());
				this.objHp.focus();
				return;
			}
			
			var tele = this.objHp.getTeleValue();
			var hp = this.objHp.getValue();
			
			var objTele = {
				"KT": 2
				, "SKT": 1
				, "LGT": 3
			}
			
			var szLink = _ROOT + "/popup/pop_auth_check.html?q_tele=" + objTele[tele] + "&q_hp=" + hp;
			
			var winHpAuth = window.open(szLink, "winHpAuth", "width=500, height=300, scrollbars=0");
			if(winHpAuth) winHpAuth.focus();
		}
	}
	
	document.objControl = new clsControl();
});